﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetfractionHub.Network.Protocol.UCMD.Factory
{
    public class FactoryCMD : ProtocolMessageFactory
    {
        public enum ParameterEnum : int
        {
            Name = 0,
            RemoveCommand = 1,
            Context = 2,
            Message = 3,
            Constrained = 4,
            Separator = 5,
            Presentation = 6
        }

        public enum ConextTypesEnum : int
        {
            HubCommand = 1,
            UserListCommand = 2,
            SearchResultCommand = 4,
            FileListCommand = 8
        }

        public override ProtocolMessage Create(ProtocolMessage.MessageTypeEnum messageType, Dictionary<int, object> parameters)
        {
            ProtocolMessage proto = new ProtocolMessage(messageType, ProtocolFeatureUCMD.FeatureActions.ActionCMD);

            if (!parameters.ContainsKey((int)ParameterEnum.Name))
                return null;

            proto.Parameters.Add(new ProtocolParameter(parameters[(int)ParameterEnum.Name].ToString()));

            foreach (ParameterEnum en in parameters.Keys)
            {
                if (en != ParameterEnum.Name)
                    proto.Parameters.Add(new ProtocolParameter(GetParameterCodeForParameter((ParameterEnum)en), parameters[(int)en].ToString()));
            }

            return proto;
        }

        private string GetParameterCodeForParameter(ParameterEnum param)
        {
            switch (param)
            {
                case ParameterEnum.RemoveCommand:
                    return "RM";
                case ParameterEnum.Context:
                    return "CT";
                case ParameterEnum.Message:
                    return "TT";
                case ParameterEnum.Constrained:
                    return "CO";
                case ParameterEnum.Separator:
                    return "SP";
                case ParameterEnum.Presentation:
                    return "PR";
                default:
                    return string.Empty;
            }
        }
    }
}
